<%--<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">--%>
<%--<html>--%>
<%--<head>--%>
<%--<meta http-equiv="Content-Type" content="text/html; charset=utf-8">--%>
<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" />--%>
<%--<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js" type="text/javascript"></script>--%>
<%--<script src="${pageContext.request.contextPath}/js/bootstrap.min.js" type="text/javascript"></script>--%>
<%--<title>退款</title>--%>
<%--</head>--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"
         isELIgnored="false" %>
<%@ page import="com.alipay.config.*" %>
<%@ page import="com.alipay.api.*" %>
<%@ page import="com.alipay.api.request.*" %>
<%
    //获得初始化的AlipayClient
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id,
            AlipayConfig.merchant_private_key, "json", AlipayConfig.charset,
            AlipayConfig.alipay_public_key, AlipayConfig.sign_type);

    //设置请求参数
    AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();

    //商户订单号，商户网站订单系统中唯一订单号
    String out_trade_no = new String(request.getParameter("WIDTRout_trade_no").getBytes("ISO-8859-1"),
            "UTF-8");
    //支付宝交易号
    String trade_no = new String(request.getParameter("WIDTRtrade_no").getBytes("ISO-8859-1"),
            "UTF-8");
    //请二选一设置
    //需要退款的金额，该金额不能大于订单金额，必填
    String refund_amount = new String(
            request.getParameter("WIDTRrefund_amount").getBytes("ISO-8859-1"), "UTF-8");
    //退款的原因说明
    String refund_reason = new String(
            request.getParameter("WIDTRrefund_reason").getBytes("ISO-8859-1"), "UTF-8");
    //标识一次退款请求，同一笔交易多次退款需要保证唯一，如需部分退款，则此参数必传
    String out_request_no = new String(
            request.getParameter("WIDTRout_request_no").getBytes("ISO-8859-1"), "UTF-8");

    alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
            + "\"trade_no\":\"" + trade_no + "\","
            + "\"refund_amount\":\"" + refund_amount + "\","
            + "\"refund_reason\":\"" + refund_reason + "\","
            + "\"out_request_no\":\"" + out_request_no + "\"}");

    //请求
    String result = alipayClient.execute(alipayRequest).getBody();
//	Gson gson=new Gson();
//    RefundResponse refundResponse = gson.fromJson(result, RefundResponse.class);
//    System.out.println(refundResponse.getAlipay_trade_refund_response().getMsg());
//    String msg="Success";
//    String message=refundResponse.getAlipay_trade_refund_response().getMsg();
//    if (message.equals(msg)){
//        response.sendRedirect("/order/reFoundUpdateOrderState.do?oid="+out_trade_no+"");
//    }else {
//        out.println(result);
//    }
    out.println(result);
%>
<%--<body>--%>
<%--</body>--%>
<%--</html>--%>